# -*- coding: utf-8 -*-
from __future__ import unicode_literals


# 舆情数据垃圾过滤
def news_filter(news_dict):
    news_title = []
    news_content = []
    ori_len = len(news_dict["event"]["hits"])
    for tmp in news_dict["event"]["hits"]:
        for kw in news_dict["alias"]["keywords"]:
            if kw in tmp["title"]:
                news_title.append(tmp)
                break
            if kw in tmp["content"]:
                news_content.append(tmp)
                break
    news_title = sorted(news_title, key=lambda x: x["event_time"], reverse=True)
    news_content = sorted(news_content, key=lambda x: x["event_time"], reverse=True)
    news_title.extend(news_content)
    news_dict["event"]["hits"] = news_title
    news_dict["event"]["total"] -= ori_len - len(news_title)
    return news_dict
